using System;
using System.Collections.Generic;
using System.Text;
using Castle.ActiveRecord;
using EYDIngenieria.ERP.ObjetosDeNegocio.Dominio;
using NHibernate.Expression;

namespace EYDIngenieria.ERP.ObjetosDeNegocio.Repositorio
{
    public class RepositorioCheque
    {
        public void Agregar(Cheque o)
        {
            o.Create();
        }

        public Cheque[] Listar()
        {
            return ActiveRecordBase<Cheque>.FindAll();
        }
        public Cheque[] Listar(Chequera c)
        {
            return Cheque.FindAllByProperty("Chequera", "Chequera", c);
        }

        public Cheque[] ListarDisponibles(Chequera c)
        {
            ICriterion[] query = { Expression.Eq("Monto", long.Parse("0")), Expression.Eq("Chequera", c) };
            Order[] sort = { Order.Asc("Monto") };
            return ActiveRecordBase<Cheque>.FindAll(sort, query);
        }

        public Cheque[] ListarDisponibles()
        {
            ICriterion[] query = { Expression.Eq("Monto",long.Parse("0")) };
            Order[] sort = { Order.Asc("Monto") };
            return ActiveRecordBase<Cheque>.FindAll(sort, query);
        }
       

        public void Modificar(Cheque o)
        {
            o.UpdateAndFlush();
        }

        public void Eliminar(Cheque o)
        {
            o.DeleteAndFlush();
        }

        
        public Cheque Obtener(int id)
        {
            return Cheque.Find(id);
        }
    }
}
